﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using aDream.Domain;


namespace aDream.Boundary.Staff
{
    public partial class StaffMenu : Form
    {
        private RealEstateAgency rea;
        public StaffMenu(RealEstateAgency rea)
        {
            InitializeComponent();
            this.rea = rea;
            addAllPropertys();
            buildTypes();
            buildStates();
        }

        private void addAllPropertys()
        {
            propertyList.DataSource = rea.getPropertys().getProperties();
        }
        private void buildTypes()
        {
            propertyType.Items.Add(new Item("Apartment"));
            propertyType.Items.Add(new Item("Town House"));
            propertyType.Items.Add(new Item("House"));
            propertyType.Items.Add(new Item("Multiplex"));
            propertyType.Items.Add(new Item("Association"));
            propertyType.Items.Add(new Item("Community Home"));
            propertyType.Items.Add(new Item("Commercial"));
            propertyType.Items.Add(new Item("Storage Facility"));
        }

        private void buildStates()
        {
            states.Items.Add(new Item("NSW"));
            states.Items.Add(new Item("VIC"));
            states.Items.Add(new Item("SA"));
            states.Items.Add(new Item("WA"));
            states.Items.Add(new Item("TAS"));
            states.Items.Add(new Item("NT"));
            states.Items.Add(new Item("QLD"));
            states.Items.Add(new Item("ACT"));
        }


        private void addButton_properties_Click(object sender, EventArgs e)
        {
            rea.getPropertys().addNewProperty(propertyType.Text, description.Text, details.Text, streetNo.Text, streetName.Text, suburb.Text, postCode.Text, states.Text);
            clear();
            addAllPropertys();
        }

        

        private void clear()
        {
            propertyType.SelectedIndex = -1;
            states.SelectedIndex = -1;
            streetNo.Clear();
            streetName.Clear();
            suburb.Clear();
            postCode.Clear();
            description.Clear();
            details.Clear();
            propertyList.DataSource = rea.getPropertys().getProperties();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Property propety = (Property)propertyList.SelectedItem;
            rea.getPropertys().delete(propety.Id);
            clear();
            addAllPropertys();
        }



        private class Item
        {

            private String value;

            public Item(String value)
            {
                this.value = value;
            }

            public override string ToString()
            {
                return value;
            }
        }

        private void propertyList_SelectedIndexChanged(object sender, EventArgs e)
        {
            Property property = (Property) propertyList.SelectedItem;
            Console.Write(property.ToString());
        }
    }
}
